/*
 * Copyright 2008 Carnegie Mellon University
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package edu.cmu.lti.sepia.infra.run.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import edu.cmu.lti.sepia.data.xml.IXmlSerializable;

public class QuestionAnalysisResult implements IXmlSerializable {

	protected List<AnswerType> answerTypes;
	protected List<Term> keyterms;
	
	public QuestionAnalysisResult( AnswerType answerType, List<Term> keyterms ) {
		this.answerTypes = new ArrayList<AnswerType>(1);
		this.answerTypes.add(answerType);
		this.keyterms = keyterms;
	}
	
	public QuestionAnalysisResult() {
		this.answerTypes = new ArrayList<AnswerType>();
		this.keyterms = new ArrayList<Term>();
	}
	
	public void addAnswerType( AnswerType atype ) {
		answerTypes.add( atype );
	}

  public void addAnswerTypes(Collection<AnswerType> atypes) {
    answerTypes.addAll(atypes);
  }
  
  public void addTerm(Term term) {
    keyterms.add(term);
  }

  public void addTerms(Collection<Term> terms) {
    keyterms.addAll(terms);
  }
	
	/**
	 * @return the answerType
	 */
	public List<AnswerType> getAnswerTypes() {
		return answerTypes;
	}
	
	/**
	 * @return the answerTypes
	 */
	public AnswerType getAnswerType() {
	  return getMostLikelyAnswerType();
	}

	/**
	 * @return the most likely answer type
	 */
	public AnswerType getMostLikelyAnswerType() {
	  AnswerType argmax = null;
	  double max = Double.NEGATIVE_INFINITY ;
	  for (AnswerType atype : answerTypes) {
	    if (max < atype.getScore()) {
	      max = atype.getScore();
	      argmax = atype;
	    }
	  }
		return argmax;
	}

	/**
	 * @return the keyterms
	 */
	public List<Term> getKeyterms() {
		return keyterms;
	}
	
}
